// house_pkg/pages/room/index.ts
Page({
  data: {
    point: '', // 小区信息
    building: '', // 楼栋信息
    rooms: [] // 房间数组
  },
  onLoad(params) {
    const point = decodeURIComponent(params.point)
    const building = decodeURIComponent(params.building)
    // 随机房间号：1（楼层）0（固定的）7（房间号码）、20（楼层）0（固定的）8（房间号码）
    this.fake(point, building)
  },
  fake(point, building) {
    // size => 总共需要多少房间
    const size = wx.utils.getRandomIntInclusive(4, 8)
    // 生成的房间号的数组
    const rooms = []
    for (let i = 0; i < size; i++) {
      const floor = wx.utils.getRandomIntInclusive(1, 20)
      const no = wx.utils.getRandomIntInclusive(1, 5)
      const room = [floor, 0, no].join('')
      // continue => 跳过本次循环，继续下一次
      if (rooms.includes(room)) continue
      rooms.push(room)
    }

    this.setData({
      point,
      building,
      rooms
    })
  },
  goForm(ev) {
    const {
      point,
      building
    } = this.data
    wx.navigateTo({
      url: `/house_pkg/pages/form/index?point=${point}&building=${building}&room=${ev.mark.room}`,
    })
  }
})